The present invention relates to circularly wrapping trace buffers, and more specifically, to methods and systems for serializing wrapping of a trace buffer via a compare-and-swap (CS) instruction.
Trace buffers are often split into blocks of storage which when full can be written externally and/or reused once all writers have finished adding data. In general, when concurrently writing to a circularly wrapping trace buffer from multiple threads, serialization is performed to reserve space and prevent wrapping of the buffer. However, when reserving space for a thread it is difficult to know if other threads are done before allowing wrapping back to that block. Accordingly, there is a risk of writing to a block that is currently being used by another thread.
Existing solutions include using a system lock to ensure that only one write can happen at a time and allowing a thread to reserve space to indicate interest in the current trace block. However, using and waiting for such a system lock can have a negative impact on system performance. Another existing solution is to disable all interrupts while reserving space so it is done quickly thereby minimizing the risk that buffers could wrap during processing. However, disabling interrupts could cause a thread to monopolize a processor and requires that all buffers be in real storage and not paged to an external device.